package fun.shuofeng.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author 朔风
 * @date 2024-02-29 21:14
 */
public class CompletableFutureAPI2Demo {
    public static void main(String[] args) throws InterruptedException {

        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 1;
        }).thenApply(res -> {
            System.out.println("111");
            return res + 1;
        }).thenApply(res -> {
            System.out.println("222");
            return res + 1;
        }).thenApply(res -> {
            System.out.println("333");
            return res + 1;
        }).whenComplete((v, e) -> {
            if (e == null) {
                System.out.println(v);
            }
        });

        System.out.println("---主线程去忙其他的了....");
        TimeUnit.SECONDS.sleep(2);

    }
}
